﻿using AutoMapper;
using MiniErp.Entity.DataStreams.DOs;
using MiniErp.Entity.DataStreams.DOs.AssetManagement;
using MiniErp.Entity.DataStreams.DOs.Notice;
using MiniErp.Entity.DataStreams.DTOs;
using MiniErp.Entity.DataStreams.DTOs.AssetManagement;
using MiniErp.Entity.DataStreams.DTOs.Notice;
using MiniErp.Entity.DataStreams.DTOs.Rights;
using MiniErp.Entity.DataStreams.DTOs.Users;
using System;
using System.Collections.Generic;

namespace MiniErp.Common.AutoMapperConfig
{
    public class ProfileConfig : Profile
    {
        /// <summary>
        /// AutoMapper配置映射类
        /// </summary>
        public ProfileConfig()
        {
            CreateMap<UserInfo, UserDTO>()
                .ReverseMap();
            CreateMap<UserInfo, RegisterDTO>()
                .ReverseMap();

            #region AssetManagement
            CreateMap<AssetInfo, AssetInfoDTO>()
             .ForMember(items => items.AllId, item => item.MapFrom(o => o.GeneralTypeId.ToString() + o.SecondaryTypeId.ToString() + o.AId.ToString()))
             .ForMember(items => items.AssetStateName, item => item.MapFrom(o => o.AssetState.AssetStateName))
             .ForMember(items => items.DepartmentName, item => item.MapFrom(o => o.Department.DepartmentName))
             .ForMember(items => items.PositionName, item => item.MapFrom(o => o.Position.PositionName))
             .ForMember(items => items.UserInfoName, item => item.MapFrom(o => o.UserInfo.UserName))
             .ReverseMap();
            CreateMap<AssetInfo, AddAssetInfoDTO>()
                .ReverseMap();
            CreateMap<UpdateAssetInfoDTO, AssetInfo>()
                  .ForMember(items => items.AllId, item => item.MapFrom(o => o.GeneralTypeId.ToString() + o.SecondaryTypeId.ToString() + o.AId.ToString()))
                  //  .ForMember(items => items.AssetStateId, item => item.MapFrom(o => o.AssetStateId))
                  .ReverseMap();
            CreateMap<AssetModificationRecord, AddAssetInfoDTO>()
            .ForMember(items => items.UserInfoId, item => item.MapFrom(o => o.UserId))
              .ReverseMap();
            CreateMap<AssetInfo, AssetModificationRecord>()
                 .ForMember(items => items.UserId, item => item.MapFrom(o => o.UserInfoId))
                  .ForMember(items => items.UserName, item => item.MapFrom(o => o.UserInfo.UserName))
                .ReverseMap();
            CreateMap<AssetModificationRecord, UpdateAssetInfoDTO>()
                 .ForMember(items => items.UserInfoId, item => item.MapFrom(o => o.UserId))
                .ReverseMap();
            CreateMap<AssetModificationRecord, AssetModificationRecordDTO>()
               .ForMember(items => items.AMTName, item => item.MapFrom(o => o.assetModificationType.AMTName))
                 .ForMember(items => items.Remarks, item => item.MapFrom(o => o.assetModificationType.Remarks))
              .ReverseMap();

            #endregion
            #region Rights
            CreateMap<JobsSystemsRights, AddRightsDTO>()
               .ReverseMap();
            CreateMap<JobsSystemsRights, RightsDTO>()
             .ReverseMap();

            #endregion
            #region Notices
            CreateMap<Notices, AddNoticesDTO>()
                 .ReverseMap();
            CreateMap<Notices, NoticesDTO>()
                 .ForMember(items => items.UserName, item => item.MapFrom(o => o.UserInfo.UserName))
                .ReverseMap();
            CreateMap<Notices, UpdateNoticesDTO>()
              .ReverseMap();

            CreateMap<UserInfoNoticesReply, AddUserInfoNoticesReplyDTO>()
               .ReverseMap();
            CreateMap<UserInfoNoticesReply, UserInfoNoticesReplyDTO>()
                .ReverseMap();
            CreateMap<UserInfoNoticesReply, UpdateUserInfoNoticesReplyDTO>()
              .ReverseMap();
            #endregion

        }

    }
}
